﻿using Mengsk.ProxyDelivery.Service;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace Mengsk.ProxyDelivery.App.UI.Accounting
{
    /// <summary>
    /// Interaction logic for SellerWithdrawalWindow.xaml
    /// </summary>
    public partial class SellerWithdrawalWindow : Window
    {
        internal SellerWithdrawalVM SellerWithdrawal { get; set; }

        public SellerWithdrawalWindow()
        {
            InitializeComponent();
        }



        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                this.tbId.Text = this.SellerWithdrawal.Source.Id.ToString();
                this.tbMoney.Text = SellerWithdrawal.Source.Money.ToString();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                this.DialogResult = false;
            }
        }

        private void btnOK_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                string comment = this.tbComment.Text.Trim();
                if (string.IsNullOrWhiteSpace(comment))
                {
                    MessageBox.Show("描述不能为空");
                    return;
                }
                bool success = this.chkOK.IsChecked == null ? false : this.chkOK.IsChecked.Value;
                var iService = ServiceContainer.GetService<SellerWithdrawalService>();
                iService.Complete(this.SellerWithdrawal.Source.Id, this.SellerWithdrawal.Source.SellerId, comment, success);
                this.SellerWithdrawal.State = this.SellerWithdrawal.Source.State = success ? Mengsk.ProxyDelivery.Domain.SellerWithdrawsState.Success : ProxyDelivery.Domain.SellerWithdrawsState.WithdrawsFailed;
                this.SellerWithdrawal.Source.Comment = comment;
                this.SellerWithdrawal.Source.CompleteOperator += App.LoginOperator.Number;
                MessageBox.Show("处理完成");
                this.DialogResult = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

    }
}
